var SdsOPQcincase = {
    episodeId: 0,
    id: 0,
    value: null

};

$(function () {
    $.parser.parse(); // 解析整个页面
    var UpAdmin=false; //默认不可上传
    $HUI.combobox('#Hospital',
        {
            data:$.parseJSON($("#officeMap").val()),
            valueField:'value',
            textField:'text',
            onSelect:SdsOPQcincase.officeChange,
            onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
                var val = $(this).combobox("getData");
                if(val.length==2){//如果就一个院区 加上全部=2
                    $(this).combobox("setValue", val[1].value);
                    SdsOPQcincase.officeChange(val[1]);
                    $("#oneOffice").val("yes");
                }else{
                    $(this).combobox("setValue", "");
                    $("#oneOffice").val("no");
                }
            }
        } )
    $HUI.combobox('#QCDic',
        {
            data:$.parseJSON($("#entityMap").val()),
            valueField:'value',
            textField:'text'
        })
    $HUI.combobox('#LocDic',
        {
            data:$.parseJSON($("#departMap").val()),
            valueField:'value',
            textField:'text',
            //目前管理医生和科室无关联
            //onSelect:SdsOPQcincase.LocChange
        })
    $HUI.combobox('#DocDic',
        {
            data:$.parseJSON($("#docMap").val()),
            valueField:'value',
            textField:'text'
        })
    $HUI.combobox('#DateType',
        {
            data:[
                {'DateType':'InEntiy','Desc':"入组日期"},
                {'DateType':'AdmDate','Desc':"就诊日期"},
                {'DateType':'UpQC','Desc':"上报日期"}
            ],
            valueField:'DateType',
            textField:'Desc',
        })
    Common_SetValue('DateType','AdmDate');
    $HUI.combobox('#Status',
        {
            data:$.parseJSON($("#statusMap").val()),
            valueField:'id',
            textField:'text',
            multiple:true,
            rowStyle:'checkbox', //显示成勾选行形式
            selectOnNavigation:false,
            blurValidValue:true,
            panelHeight:"auto",
            editable:false
        })
    var SDate = getBeforeWeekDate();
    var EDate=getNowFormatDate();
    Common_SetValue('SDate',SDate);
    Common_SetValue('EDate',EDate);
    $HUI.linkbutton('#search',{
        iconCls:'icon-w-find'
    })
    $HUI.linkbutton('#updoAll',{
        iconCls:'icon-w-msg'
    })
    var execUser = $("#execUser").val();
    if (('admin'==execUser)||('DeptManager'==execUser))
    {
        UpAdmin=true;
    }else {
        //Common_SetValue('LocDic',session['DHCMA.CTLOCID']);
        //Common_SetValue('DocDic',session['DHCMA.CarePID']);
        //$("#LocDic").combobox('disable');
        //$("#Hospital").combobox('disable');
        //$("#DocDic").combobox('disable');
        $('#updoAll').hide();
        //var frm  = dhcsys_getmenuform();
    }
    SdsOPQcincase.gridQCMrList= $HUI.datagrid("#gridQCMrList",{
        fit:true,
        pagination: true, //如果为true, 则在DataGrid控件底部显示分页工具栏
        displayMsg: "当前表格显示 {from} 到 {to} ,共 {total} 条记录",
        singleSelect: false,
        //定义是否设置基于该行内容的行高度。设置为 false，则可以提高加载性能
        autoRowHeight: false,
        striped:true,
        rownumbers:true,
        loadMsg:'数据加载中...',
        pageSize: 10,
        pageList : [10,50],
        idField:"EpisodeID",
        columns:[[
            {field:'checked',checkbox:'true',align:'left',width:30,auto:false},
            {field:'qcEntityDesc',title:'单病种',width:'200',align:'left',sortable:true},
            {field:'name',title:'患者姓名',width:'150',align:'left',sortable:false},
            {field:'registNum',title:'登记号',width:'120',align:'left'},
            {field:'eCount',title:'表单填报率',width:'120',align:'left',
                formatter: function (value, row) {
                    var tempval=((parseInt(row.eCount)*100)/(parseInt(row.eCount)+parseInt(row.nCount))).toFixed(1);
                    if (isNaN(tempval)) tempval=0
                    var htmlstr='<div style="width:100%; height:16px;border:1px solid #95B8E7;border-radius: 5px 5px 5px 5px;">'+
                        '<div style="width: '+tempval+'%; height:100%;background-color:#BEEB9F;border-radius: 5px 5px 5px 5px;">'+tempval+'%</div></div>'
                    return htmlstr;
                }
            },
            {field:'qcCurrStatus',title:'表单状态',width:'100',sortable:true,align:'center',
                formatter: function(value,row,index){
                    var ExcludeInfo=row.excludeInfo
                    var reg = new RegExp( ',' , "g" )
                    ExcludeInfo=ExcludeInfo.replace(reg,"\n")
                    //var rdModal=JSON.stringify(row)
                    if (value=="O") {
                        return '<a style="cursor:pointer" title="'+ExcludeInfo+'" class="hisui-tooltip grid-tips" onclick="SdsOPQcincase.InSDManager(\'' + row.locId + '\',\'' + row.id + '\',\'' +  row.rowId + '\')"><span style="color:red;">已排除</span></a>';
                    }else if (value=="I") {
                        return '<a title="'+ExcludeInfo+'" class="hisui-tooltip grid-tips" onclick="SdsOPQcincase.StatusToggle(\'' + value + '\',\'' + row.rowId + '\',\'' +  row.qcEntityId + '\' ,\'' + row.qcEntityDesc + '\')"><span style="color:green;">'+row.qcCurrStatusDesc+'</span></a>';
                    }else if (value==""){
                        return '<a style="cursor:pointer" class="hisui-linkbutton" onclick="SdsOPQcincase.InSDManager(\'' + row.locId + '\',\'' + row.id + '\',\'' +  row.rowId + '\')">入组单病种</a>';
                    }else{
                        if (ExcludeInfo=="") {
                            return row.qcCurrStatusDesc;
                        }else{
                            return '<a title="'+ExcludeInfo+'" class="hisui-tooltip grid-tips" >'+row.qcCurrStatusDesc+'</a>';
                        }
                    }
                }

            },
            {field:'admDoctorName',title:'管床医生',width:'150',align:'left',sortable:false},
            {field:'admDate',title:'就诊日期',width:'120',align:'left',sortable:true,
                formatter: function(value,row,index){
                    let appointDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(value)[0];
                    return appointDate;
                }
            },
            {field:'qcInDate',title:'入单日期',width:'200',align:'left',sortable:true},
            {field:'log',title:'操作日志',width:'150',align:'left',sortable:true,
                formatter: function(value,row,index){
                    var MrlistID=row.rowId
                    return " <a href='#' class='hisui-linkbutton hover-dark' style='cursor:pointer' onclick='SdsOPQcincaseOperLog.ShowLog(\""+MrlistID+ "\");'>查看</a>";
                }

            },
            {field:'rowId',title:'门诊病历',width:'150',align:'left',sortable:true,
                formatter: function(value,row,index){
                    var patientID=row.id
                    return " <a href='#' class='hisui-linkbutton hover-dark' style='cursor:pointer' onclick='SdsOPQcincaseOperLog.DisplayEPRView(\"" + patientID + "\");'>病历浏览</a>";
                }

            },
            {field:'id',title:'上传接<br/>口平台',width:'100',align:'left',id:'UpForm',sortable:true,hidden:UpAdmin?false:true,
                formatter: function(value,row,index){
                    if (row.qcCurrStatus=="Up") {
                        return '<span style="color:green;">已上传</span>';
                    }else if(row.qcCurrStatus=="Check" || row.qcCurrStatus=="tUp"){
                        return '<a href="#" class="hisui-linkbutton" onclick="SdsOPQcincase.UpForm(\'' + row.rowId + '\')">上传</a>';
                    }else{
                        //return '<a href="#" class="hisui-linkbutton" onclick=objScreen.UpForm('+row.RowID+","+"\"\""+')>上传</a>';
                        return '<a class="hisui-linkbutton" style="color:black;">待填报</a>';
                    }

                }

            }
        ]]
        ,onDblClickRow:function(rowIndex,rowData){
            if(rowIndex>-1){
                SdsOPQcincase.gridQCMrList_onDbselect(rowData);
            }
        }
        ,onLoadSuccess:function(rowData){
        }
    });
    $('#winConfirmInfo').dialog({
        title: '',
        iconCls:"icon-w-edit",
        closed: true,
        modal: true,
        isTopZindex:true
    });
    SdsOPQcincase.initGridQCMrList();
});

SdsOPQcincase.initGridQCMrList = function(){
    $('#search').click();
}

SdsOPQcincase.officeChange = function(that){
    var ajax = new $ax(Sys.backendPath + "/sds/common/deptListByHospId", function(data){
        $('#LocDic').combobox({
            data:data,
            valueField:'value',
            textField:'text',
            onLoadSuccess: function () { //加载完成后,val[0]写死设置选中第一项
                $(this).combobox("setValue", "");
            }
        });
    },function(data){
        layer.msg("查询失败!" + data.responseJSON.message + "!",{icon: 2});
    });
    ajax.set({"hospID":that.value,"id":"depart"});
    ajax.start();
}

//赋值
function Common_SetValue() {
    var itmValue = '';

    var val = arguments[1];
    var txt = arguments[2];

    if (typeof(arguments[0]) !== 'string') return '';
    if (arguments[0] == '') return '';

    var $this = $('#'+ arguments[0]);
    if ($this.length < 1) return '';
    if (typeof val == 'undefined') val = '';
    if (typeof txt == 'undefined') txt = '';

    var className = $this.attr("class").split(' ')[0];

    if (className == 'textbox') {  //文本框
        itmValue = $this.val(val);
    }else if (className == 'hisui-numberbox') {  //数字
        itmValue = $this.val(val);
    }else if (className == 'hisui-datebox') {  //日期
        itmValue = $this.datebox('setValue',val);
    }else if (className == 'hisui-timespinner') {  //时间框
        itmValue = $this.timespinner('setValue',val);
    }else if (className == 'hisui-combobox') {  //下拉框
        if(val !="" && txt ==""){
            itmValue = $this.combobox('setValue',val);
        }else{
            itmValue = $this.combobox('setValue',txt);
        }
    }else if (className == 'hisui-switchbox') {  //开关
        itmValue = $this.switchbox('setValue',val);
    }else if (className == 'hisui-checkbox') {  // 单个复选框
        if (val == '') val = 0;
        itmValue = $this.checkbox('setValue',(val) ? true : false);
    }else if (className == 'hisui-radio') {  //单个单选框
        if (val == '') val = 0;
        itmValue = $this.radio('setValue',(val) ? true : false);
    }else if (className == 'hisui-searchbox') {  //查询框框
        itmValue = $this.searchbox('setValue',val);
    }

    return itmValue;
}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}
//当前日期前七天
function getBeforeWeekDate() {
    var date = new Date();
    date = +date - 1000*60*60*24*6;
    date = new Date(date);
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

SdsOPQcincase.InSDManager=function(locId,episodeId,rowId){
    var locId=0
    //弹窗填写入组理由
    $('#divQCDic').show();
    $('#RuleDic').html("")
    Common_SetValue("RuleResume","");
    $("#winQCDic").combobox({
        url:'/sds/sdsopqcincase/selectQcEntityByLocId?aLocOId='+locId,
        method : "get",
        valueField:'value',
        textField:'text'
        ,onSelect: function () {
            var DicID=Common_GetValue('winQCDic');
            Common_CheckboxToSDRule("RuleDic",DicID,1,1);
        }
    })
    SdsOPQcincase.episodeId=episodeId
    $('#winConfirmInfo').dialog({
        title: '单病种准入信息填写',
        height: 400
    })
    SdsOPQcincase.id=rowId;
    SdsOPQcincase.value="I";
    $HUI.dialog('#winConfirmInfo').open();
}

SdsOPQcincase.StatusToggle=function(value,ID,QCID, QCDesc) {
    var saveRet=0
    if(value=="I") {
        $.messager.confirm("提示", "是否取消确认选中数据记录?", function (r) {
            if (r) {
                //弹窗选择取消确认理由，或填写备注
                //弹窗填写取消排除备注
                //$('#divQCDic').hide();
                Common_SetValue('winQCDic',QCDesc);
                $("#winQCDic").combobox('disable');
                Common_SetValue("RuleResume","");
                Common_CheckboxToSDRule("RuleDic",QCID,2,1);
                $('#winConfirmInfo').dialog({
                    title: '排除单病种信息填写',
                    height: 350
                })
                SdsOPQcincase.id=ID;
                SdsOPQcincase.value="O";
                $HUI.dialog('#winConfirmInfo').open();
            }
        });
    }
}
//门诊病历
SdsOPQcincase.DisplayEPRView=function(EpisodeID,PatientID) {
    Common_showEMR(EpisodeID,PatientID)
}

SdsOPQcincase.UpForm=function(MrListID) {
    var msginfo=""
    $.messager.progress({
        title: "提示",
        msg: '正在上传数据',
        text: '上传中....'
    });
    var ajax = new $ax("/sds/sdsqcformshow/upload/" + MrListID, function (UpRet) {
        $.messager.progress("close");
        if (UpRet.code == 1) {
            $.messager.popover({
                msg: '上传成功！',
                type: 'success',
                timeout: 1000,
                style: {
                    top: ($(window).height() - 50) / 2 + $(document).scrollTop(),
                    left: ($(window).width() - 140) / 2 + $(document).scrollLeft()
                }
            })
            //更新状态
            var ax = new $ax("/sds/sdsqcformshow/changeMrStatus", function (data) {
                $.messager.popover({
                    msg: '状态更新成功！',
                    type: 'success',
                    timeout: 1000,
                    style: {
                        top: ($(window).height() - 50) / 2 + $(document).scrollTop(),
                        left: ($(window).width() - 140) / 2 + $(document).scrollLeft()
                    }
                })
                $('#gridQCMrList').datagrid('reload');
            }, function (data) {
                $.messager.alert("错误提示", "状态更新错误!", 'info');
            });
            ax.set('mrListId', MrListID);
            ax.set('status', "Up");
            /*ax.set('execUser', $("#execUser").val())
            ax.set('execUserId', $("#execUserId").val())*/
            ax.set('reason', '');
            ax.set('resume', '');
            ax.start();
        } else if (UpRet.message.indexOf('重复') > -1) {
            //更新状态
            var ax = new $ax("/sds/sdsqcformshow/changeMrStatus", function (data) {
                $.messager.popover({
                    msg: '已存在上传记录，状态更新成功！',
                    type: 'success',
                    timeout: 1000,
                    style: {
                        top: ($(window).height() - 50) / 2 + $(document).scrollTop(),
                        left: ($(window).width() - 140) / 2 + $(document).scrollLeft()
                    }
                })
                $('#gridQCMrList').datagrid('reload');
            }, function (data) {
                $.messager.alert("错误提示", "已存在上传记录，状态更新错误!", 'info');
            });
            ax.set('mrListId', MrListID);
            ax.set('status', "Up");
            /*ax.set('execUser', $("#execUser").val())
            ax.set('execUserId', $("#execUserId").val())*/
            ax.set('reason', '');
            ax.set('resume', '');
            ax.start();
        } else {
            console.log(UpRet);
            $.messager.alert("错误提示", "表单上传失败!Error=" + UpRet.message, 'info');
        }
    }, function (data) {
        $.messager.alert("错误提示", "表单上传失败!", 'info');
    });
    ajax.setAsync();
    ajax.start();
}

SdsOPQcincase.gridQCMrList_onDbselect = function(rd) {
    if (rd.rowId=="") {
        $.messager.alert('提示',"当前患者尚未入组！",'info');
        return;
    }
    var title="病种名称："+rd.qcEntityDesc+" /登记号："+rd.registNum+" /姓名："+rd.name+" /就诊日期："+rd.admDate;
    var index = Sys.open_c(title, '/sds/sdsqcformshow?mrListId=' + rd.rowId+ '&checkPerm=' + 1, null, function (){
    });
    this.layerIndex = index;
}

$('#Export').on('click',function () {
    /*var rows=$("#gridQCMrList").datagrid('getRows').length;
    if (rows>0) {
        $('#gridQCMrList').datagrid('toExcel','单病种表单.xls');
    }else {
        $.messager.alert("确认", "无数据记录,不允许导出", 'info');
        return;
    }*/
    //前端导出改完后端导出
    var rows=$("#gridQCMrList").datagrid('getRows').length;
    if (rows>0) {
        window.location.href ='/sds/sdsopqcincase/export';
    }else {
        $.messager.alert("确认", "无数据记录,不允许导出", 'info');
        return;
    }
})
$('#search').on('click',function () {
    var StatusStr=$('#Status').combobox('getValues').join(',');
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/sds/sdsopqcincase/selectQCOPMrListByDate", function (data) {
        //加载表格数据
        $('#gridQCMrList').datagrid({loadFilter:pagerFilter}).datagrid('loadData', data);
    }, function (data) {
    });
    params.aHospID = Common_GetValue('Hospital');
    params.aLocID = Common_GetValue('LocDic');
    params.aDocID = Common_GetValue('DocDic');
    params.aQCEntity = Common_GetValue('QCDic');
    params.aStatus = StatusStr;
    params.aDateFrom = Common_GetValue('SDate');
    params.aDateTo = Common_GetValue('EDate');
    params.aDateType = Common_GetValue('DateType');
    params.aRegNo = Common_GetValue('RegNo');
    ajax.set(params);
    ajax.start();
})

$('#RegNo').on('keydown',function (e) {
    if (e.keyCode == 13) {
        $('#search').click();
    }
});
$('#updoAll').on('click',function () {
    var selectRows = $("#gridQCMrList").datagrid('getChecked');
    if (selectRows.length == 0) {
        Sys.error("请选择要上报的病例！");
        return;
    }
    $.messager.progress({
        title: "提示",
        msg: '正在上传数据',
        text: '上传中....'
    });
    var message = "";
    var successCnt = 0;
    var errorCnt = 0;
    for (var i = 0, l = selectRows.length; i < l; i++) {
        var row = selectRows[i];
        var id = row.rowId;
        var mrNo = row.mrNum;
        var name = row.name;
        var ajax = new $ax(Sys.backendPath + "/sds/sdsqcformshow/upload/" + id, function (UpRet) {
            if (UpRet.code == 1) {
                //更新状态
                var ax = new $ax(Sys.backendPath + "/sds/sdsqcformshow/changeMrStatus", function (data) {
                });
                // // 如果返回信息Code为“1”，且无message信息，则说明前置机该病种为测试状态，将该入组记录加个测试上报标识
                // if (UpRet.message == null || UpRet.message == "") {
                //     ax.set('testFlg', 1);
                // }
                ax.set('mrListId', id);
                ax.set('status', 'Up');
                ax.start();
                successCnt++;
            } else if (UpRet.message.indexOf('重复') > -1) {
                //更新状态
                var ax = new $ax(Sys.backendPath + "/sds/sdsqcformshow/changeMrStatus", function (data) {
                });
                ax.set('mrListId', id);
                ax.set('status', 'Up');
                ax.set('reason', '');
                ax.set('resume', '');
                ax.start();
                successCnt++;
            } else {
                message += name + "(" + mrNo + ")：" + UpRet.message + "<br>";
                errorCnt++;
            }
        }, function (UpRet) {
            message += name + "(" + mrNo + ")：表单上传失败!";
            errorCnt++;
        });
        ajax.start();
    }
    $.messager.progress("close");

    $.messager.alert("上报结果", "成功例数：" + successCnt + " " + "错误例数：" + errorCnt + "<hr>" + message, 'info');

    $('#gridQCMrList').datagrid('reload');
    });

$('#SaveRule').on('click',function () {
    if (SdsOPQcincase.value!="O") {
        SdsOPQcincase.NewEntryQC()
    }else{
        var RuleStr=Common_CheckboxValue('RuleDic')
        var Resume=$('#RuleResume').val()
        if ((RuleStr=="")&&(Resume=="")) {
            $.messager.alert("错误提示","请选择准入准出规则或者填写备注！", 'info');
            return
        }
        var params = {};
        var ajax = new $ax(Sys.backendPath + "/sds/sdsqcformshow/changeMrStatus", function (data) {
            $.messager.popover({msg: '操作成功！',type:'success',timeout: 1000});
            $('#search').click();
        }, function (data) {
            $.messager.alert("错误提示","操作失败!", 'info');
            return; //如果主记录保存失败  退出
        });
        params.mrListId = SdsOPQcincase.id;
        params.status = SdsOPQcincase.value;
        params.reason = RuleStr;
        params.resume = Resume;
        ajax.set(params);
        ajax.start();
        /*var RuleInputStr=obj.ID+"^"+obj.value+"^"+session['LOGON.USERID']+"^"+RuleStr+"^"+Resume
        var flg = $m({
            ClassName:"DHCMA.CPW.SDS.QCMrListStateSrv",
            MethodName:"ChangeMrlistSatus",
            aInput:RuleInputStr
        },false);
        if (parseInt(flg) < 0) {
            $.messager.alert("错误提示","操作失败!Error=" + flg, 'info');
        } else {
            $.messager.popover({msg: '操作成功！',type:'success',timeout: 1000});
            $('#search').click();
        }*/
        $HUI.dialog('#winConfirmInfo').close();
    }
})
//新入病种
SdsOPQcincase.NewEntryQC=function () {
    /*if (session['DHCMA.CTLOCID']==undefined) {
        var InLocID=session['LOGON.CTLOCID']
    }else{
        var InLocID=session['DHCMA.CTLOCID']
    }
    if (session['DHCMA.USERID']==undefined) {
        var InUserID=session['LOGON.USERID']
    }else{
        var InUserID=session['DHCMA.USERID']
    }*/
    var RuleStr=Common_CheckboxValue('RuleDic')
    var Resume=$('#RuleResume').val()
    if ((RuleStr=="")&&(Resume=="")) {
        $.messager.alert("错误提示","入组原因和备注最少填写一项！", 'info');
        return;
    }
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/sds/sdsopqcincase/inQcEntity", function (data) {
        if (parseInt(data)<1) {
            $.messager.alert("错误提示","入单病种失败!", 'info');
            return; //如果主记录保存失败  退出
        }else {
            $.messager.popover({msg: '操作成功！',type:'success',timeout: 1000});
            $('#search').click();
        }
    }, function (data) {
    });
    params.episodeId = SdsOPQcincase.episodeId;
    params.qcDicId = Common_GetValue('winQCDic');
    params.ruleStr = RuleStr;
    params.resume = Resume;
    ajax.set(params);
    ajax.start();
    $HUI.dialog('#winConfirmInfo').close();
}

$('#CanCelRule').on('click',function(){$HUI.dialog('#winConfirmInfo').close();})

function Common_GetValue()
{
    var itmValue = '';

    if (typeof(arguments[0]) !== 'string') return '';
    if (arguments[0] == '') return '';

    var $this = $('#'+ arguments[0]);
    if ($this.length < 1) return '';

    var className = $this.attr("class").split(' ')[0];

    if (className == 'textbox') {  //文本框
        itmValue = $this.val();
    }else if (className == 'hisui-numberbox') {  //数字
        itmValue = $this.val();
    }else if (className == 'hisui-datebox') {  //日期
        itmValue = $this.datebox('getValue');
    }else if (className == 'hisui-timespinner') {  //时间框
        itmValue = $this.timespinner('getValue');
    }else if (className == 'hisui-combobox') {  //下拉框（多选下拉框没有封装）
        itmValue = $this.combobox('getValue');
    }else if (className == 'hisui-switchbox') {  //开关
        itmValue = $this.switchbox('getValue');
    }else if (className == 'hisui-checkbox') {  // 单个复选框
        itmValue = $this.checkbox('getValue');
    }else if (className == 'hisui-radio') {  //单个单选框
        itmValue = $this.radio('getValue');
    }else if (className == 'hisui-searchbox') {  //查询框框
        itmValue = $this.searchbox('getValue');
    }

    return itmValue;
}

function pagerFilter(data) {
    if (typeof data.length == 'number' && typeof data.splice == 'function') {// is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {pageNumber: pageNum, pageSize: pageSize});
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}

function Common_CheckboxToSDRule() {
    var ItemCode = arguments[0];
    var ParRef	 = arguments[1];
    var RuleType = arguments[2];
    var columns	 = arguments[3]? arguments[3] : 4;;
    /*var strDicList =$m({
        ClassName:"DHCMA.CPW.SDS.QCEntityMatchRuleSrv",
        MethodName:"GetRulesByParref",
        aParRef:ParRef,
        aRuleType:RuleType
    },false);*/
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/sds/sdsopqcincase/selectRulesByQcEntityId", function (data) {
        //加载表格数据
        var dicList = data.split(";");
        if (dicList[0]=="") {$('#'+ItemCode).html(""); return;}
        var len =dicList.length;
        var count = parseInt(len/columns)+1;
        var per = Math.round((1/columns) * 100) + '%';  //每列所在百分比，等比分布

        var listHtml=""
        for (var index =0; index< count; index++) {
            var chklen=(((index+1)*columns)<len) ? (index+1)*columns : len;
            listHtml +="<div>";
            for (var dicIndex = index*columns; dicIndex < chklen; dicIndex++) {
                var dicSubList = dicList[dicIndex].split(",");

                listHtml += "<div style='overflow: auto;float:left;width:"+per+"'><input id="+ItemCode+dicSubList[0]+" type='checkbox' class='hisui-checkbox' "+(dicSubList[0]==1? "checked='true'":"")+" label= '"+dicSubList[1]+"'  name="+ItemCode+"  value="+dicSubList[0]+"></div>";
            }
            listHtml +="</div>"
        }
        $('#'+ItemCode).html(listHtml);
        $.parser.parse('#'+ItemCode);  //解析checkbox
    }, function (data) {
    });
    params.qcEntityId = ParRef;
    params.ruleType = RuleType;
    ajax.set(params);
    ajax.start();
}

//多选字典取值 Common_CheckboxValue("chkStatusList")
function Common_CheckboxValue() {
    var ItemCode = arguments[0];
    var value = "";
    $("input[name='"+ItemCode+"']:checked").each(function(){
        value = value + $(this).val()+ ",";
    });
    if (value!="") { value = value.substring(0, value.length-1); }

    return value;
}